package com.xbw.controller;

import java.io.File;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

public  class CraeteQRCode {
  
	static	int width=300; //宽度
	static	int height=300; //高度
	static	String format="png";//格式
 		//定义二维码参数
	public static  void get(File fe,String contents){
		 Date date=new Date();
		   SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
		HashMap hints=new HashMap();
		hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
		hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.M);
		hints.put(EncodeHintType.MARGIN, 2);
		
		try {
		BitMatrix 	bitMatrix=new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height,hints);
		
        Path file=fe.toPath();
        MatrixToImageWriter.writeToPath(bitMatrix, format, file);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
}
